package com.movitech.mobile.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class Swagger2 {
    @Bean
    public Docket createRestApi() {
        List apiKeys = new ArrayList<ApiKey>();
        apiKeys.add(apiKey());
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.movitech.mobile.cz.base"))
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(apiKeys);
    }


    private ApiKey apiKey() {
        return new ApiKey("x-auth-token", "token", "header");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("服务接口")
                .description("")
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }
}
